package cn.kgc.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 课工场
 * @date 2025/1/13
 * @description
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {


    @GetMapping("m1/{id}")
    @HystrixCommand(fallbackMethod = "method1Fallback")
    public String  method1(@PathVariable Integer id){
        System.out.println("=======HystrixController method1========= ");
        if (id<0){
            throw  new RuntimeException("参数异常");
        }
        return "HystrixController method1 ok";
    }

    // method1的快速响应方法   method1一旦有异常  则直接通过该方法进行处理  参数列表保持和对应方法一致
    public String  method1Fallback(Integer id){
        System.out.println("=======HystrixController method1Fallback========= ");
        return "参数异常,id="+id;
    }



}
